package appinfo.service;


import appinfo.mapper.AppInfoMapper;
import appinfo.pojo.AppInfo;
import appinfo.pojo.vo.AppSearchVo;
import appinfo.util.PageBean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;

/**
 * @author lzfei
 **/
@Service
public class AppInfoServiceImpl implements AppInfoService {

    @Resource
    private AppInfoMapper appInfoMapper;
    @Override
    public PageBean<AppInfo> findPage(AppSearchVo vo) {
        PageBean<AppInfo> pages = new PageBean<>();
        pages.setPageNo(vo.getPageIndex());
        pages.setPageSize(vo.getPageSize());
        pages.setResult(appInfoMapper.findAppInfo(vo));
        pages.setTotalCount(appInfoMapper.findCount(vo));

        return pages;
    }

    @Override
    public AppInfo findApp(String aid) {

        Integer id = Integer.parseInt(aid);
        return appInfoMapper.findApp(id);
    }

    @Override
    public Boolean update(String id, String status) {
        Integer aid = Integer.parseInt(id);
        Integer astatus = Integer.parseInt(status);
        if (appInfoMapper.update(aid,astatus)>0){
            return true;
        }
        return false;
    }

    @Override
    public AppInfo getAppById(Integer id) {
        return appInfoMapper.getAppById(id);
    }

    @Transactional(rollbackFor = {RuntimeException.class, SQLException.class})
    @Override
    public int delApp(Integer id) {

        int count = appInfoMapper.delVersion(id);
        int count1 = appInfoMapper.delApp(id);



        return 1;
    }

    @Override
    public AppInfo findAppViewById(Integer id) {
        return appInfoMapper.findAppViewById(id);
    }

    @Override
    public int appInfoAdd(AppInfo appInfo) {

            return appInfoMapper.appInfoAdd(appInfo);

    }

    @Override
    public int selectAPKName(String apkName) {
        return appInfoMapper.selectAPKName(apkName);
    }

    @Override
    public int onAndOff(Integer appId, Integer statusapp) {
        return appInfoMapper.onAndOff(appId, statusapp);
    }

    @Override
    public int delFile(Integer id) {
        return appInfoMapper.delFile(id);
    }

    @Override
    public int updateAppById(AppInfo appInfo) {
        return appInfoMapper.updateApp(appInfo);
    }
}
